﻿//
//
//    ___    _      ___                                                       _                _
//    (  _`\ ( )    (  _`\                                                    ( )              ( )_  _
//    | | ) || |    | ( (_)   _ _   ___ ___     __      _ _    _ __   _      _| | _   _    ___ | ,_)(_)   _     ___
//    | | | )| |  _ | |___  /'_` )/' _ ` _ `\ /'__`\   ( '_`\ ( '__)/'_`\  /'_` |( ) ( ) /'___)| |  | | /'_`\ /' _ `\
//    | |_) || |_( )| (_, )( (_| || ( ) ( ) |(  ___/   | (_) )| |  ( (_) )( (_| || (_) |( (___ | |_ | |( (_) )| ( ) | _
//    (____/'(____/'(____/'`\__,_)(_) (_) (_)`\____)   | ,__/'(_)  `\___/'`\__,_)`\___/'`\____)`\__)(_)`\___/'(_) (_)(_)
//                                                    | |
//                                                    (_)
//
//    Generated at 6/9/2021 6:19:57 PM

#if DLIF_ES3

namespace GameHelper.EditorScripting
{
    public class EasySaveBugDetector
    {
#if UNITY_EDITOR
        // EasySave遗留bug检测
        [UnityEditor.Callbacks.DidReloadScripts]
        private static void UnityDidReloadScripts()
        {
            if (UnityEditor.EditorApplication.isCompiling || UnityEditor.EditorApplication.isUpdating || UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }
            var testKey = "datetimetest";
            var now = System.DateTime.Now;
            ES3.Save(testKey, now);
            var nowSaved = ES3.Load<System.DateTime>(testKey);
            ES3.DeleteKey(testKey);
            if (now.Kind != nowSaved.Kind)
            {
                // DL.EditorScripting.DLEditorUtility.DisplayError("EasySave bug, DateTime 存储异常，请更新EasySave插件");
                // UnityEngine.Debug.LogError("EasySave bug, `DateTime`类型存储异常! 请更新EasySave插件");
            }

            ES3.Save(testKey, long.MaxValue);
            var longValue = ES3.Load<long>(testKey);
            ES3.DeleteKey(testKey);
            if (longValue != long.MaxValue)
            {
                // DL.EditorScripting.DLEditorUtility.DisplayError("EasySave bug, long 存储异常，请更新EasySave插件");
                // return;
                UnityEngine.Debug.LogError("EasySave bug, `long`类型存储异常! 请更新EasySave插件");
            }

            ES3.Save(testKey, ulong.MaxValue);
            var ulongValue = ES3.Load<ulong>(testKey);
            ES3.DeleteKey(testKey);
            if (ulongValue != ulong.MaxValue)
            {
                // DL.EditorScripting.DLEditorUtility.DisplayError("EasySave bug, ulong 存储异常，请更新EasySave插件");
                // return;
                UnityEngine.Debug.LogError("EasySave bug, `ulong`类型存储异常! 请更新EasySave插件");
            }
        }
#endif
    }
}

#endif
